﻿using System.Drawing;

namespace Mic.Identity.Service
{
    public class ImageLoaderService : IImageLoaderService
    {
        private Lazy<Bitmap> _lazyImage => new Lazy<Bitmap>( () =>  LoadImageAsync("path/to/image.jpg").Result , LazyThreadSafetyMode.ExecutionAndPublication);

        public Bitmap GetImage()
        {
            return _lazyImage.Value;
        }

        public async Task<Bitmap> LoadImageAsync(string imagePath)
        {
            using (var stream = new FileStream(imagePath, FileMode.Open))
            {
                return (Bitmap)Image.FromStream(stream);
            }
        }

        //Task<Bitmap> IImageLoaderService.LoadImageAsync(string imagePath)
        //{
        //    throw new NotImplementedException();
        //}
    }
}
